//
// Created by Win on 2017/1/19.
//
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frmem.h"
#include "frbyte_buffer.h"

#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_cunit.h"
#include "apmtest_comm.h"
#include "frhessian.h"

extern char* frhessian_read_head(Frbyte_Packet *p_st_data, Frreport_body_data *p_st_body_data
        , int i_use_request, char *p_prefix, hessian_parse *p_st_parse);

static int __suite_init(void)
{
    
    return 0;
}

static int __suite_cleanup(void)
{
    
    return 0;
}


static void __case1(void)
{
    
    char *p_ret = NULL;
    
    p_ret = frhessian_read_head(NULL, NULL, FR_NO, NULL, NULL);
    
    CU_ASSERT_PTR_NULL(p_ret);
    
    return;
    
}


static void __case2(void)
{
    
    char *p_ret = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;
    Frbyte_Packet *p_st_data = NULL;
    hessian_parse st_parst = {FR_NO, -1, 0};
    
    apmtest_create_ct(&p_st_conn, NULL, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);
    
    p_st_data = bytebuff_creat();
    
    bytebuff_add(p_st_data, (char *)"\x48\x00\x02\x31\x31", 5);
    
    p_ret = frhessian_read_head(p_st_data, p_st_body_data, FR_YES, (char *)"http.hessian", &st_parst);
    
    CU_ASSERT_STRING_EQUAL(p_ret, "11");
    frfree(p_ret);
    
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);
    bytebuff_free(&p_st_data);
    
    return;
    
}


int add_suite_frhessian_read_head(void)
{
    CU_pSuite pSuite = NULL;
    
    if ((pSuite = CU_add_suite("frhessian.c frhessian_read_head()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;
    
    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    
    
    return FR_SUCC;
    
}